package page;

import javax.servlet.http.HttpServletRequest;
/*
 * PageBean:包含用于分页参数信息的类
 */
public class PageBean {
	int currentPageIndex=1;//需要查询的页面序号
	int pageSize;//每页显示的记录数量
	int sortIndex=0;//排序字段的序号，从0开始，对应于jsp中的表格列序号
	String sortDirection="asc";//排序方向
	String pageParameterName;//客户端传递来的包含页面序号的参数名
	String sortIndexParameterName;//客户端传递来的包含排序列序号的参数名
	String directionParameterName;//客户端传递来的包含排序方向的参数名
	String pageSizeParameterName="pagesize";//每页最大记录数参数名称
	HttpServletRequest request;
	public PageBean(){
		currentPageIndex=0;
		sortIndex=0;
		pageSize=10;
	}
	public void setCurrentPageIndex(int value){
		this.currentPageIndex=value;
	}
	public int getCurrentPageIndex(){
		return this.currentPageIndex;
	}
	public void setPageSize(int value){
		this.pageSize=value;
	}
	public int getPageSize(){
		return this.pageSize;
	}
	public void setSortIndex(int value){
		this.sortIndex=value;
	}
	public int getSortIndex(){
		return this.sortIndex;
	}
	public void setSortDirection(String value){
		this.sortDirection=value;
	}
	public String getSortDirection(){
		return this.sortDirection;
	}
	public void setPageParameterName(String value){
		this.pageParameterName=value;
	}
	public String getPageParameterName(){
		return this.pageParameterName;
	}
	public void setSortIndexParameterName(String value){
		this.sortIndexParameterName=value;
	}
	public String getSortIndexParameterName(){
		return this.sortIndexParameterName;
	}
	public void setDirectionParameterName(String value){
		this.directionParameterName=value;
	}
	public String getDirectionParameterName(){
		return this.directionParameterName;
	}
	public void setPageSizeParameterName(String value)
	{
		this.pageSizeParameterName=value;
	}
	public String getPageSizeParameterName()
	{
		return this.pageSizeParameterName;
	}
	public void setRequest(HttpServletRequest request){
		this.request=request;
		if(this.request!=null){//从request中获取并初始化分页参数
			if(request.getParameter(this.pageParameterName)!=null)
				this.setCurrentPageIndex(Integer.parseInt(this.request.getParameter(this.pageParameterName)));
			if(request.getParameter(this.sortIndexParameterName)!=null)
				this.setSortIndex(Integer.parseInt(this.request.getParameter(this.sortIndexParameterName)));
			if(request.getParameter(this.directionParameterName)!=null)
				this.setSortDirection(this.request.getParameter(this.directionParameterName));
			if(request.getParameter(this.pageSizeParameterName)!=null&&(!request.getParameter(this.pageSizeParameterName).equals("0")))
			{
;				String p=this.request.getParameter(this.pageSizeParameterName);
				this.setPageSize(Integer.parseInt(this.request.getParameter(this.pageSizeParameterName)));
			}
		}
	}
	public HttpServletRequest getRequest(){
		return this.request;
	}
	
}
